// pages/CoureseDetailCourse/CoureseDetailCourse.js

Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    imageUrl:'../image/icon/icon_3.png',
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    haveLogin:false,
    videoPath:'http://sandcolleges.zero2ipo.com.cn/vc-talk-video/1518320199255.mp4',
    videoIndex:'1',
    play:false,
    playState:'播放',
    playStateBool:false,
    isHaveGetUserInfo:false,
  },
  
  clickToLook:function(e)
  {
    var that = this;
    console.log('11111 ' + this.data.playStateBool + '12' + this.data.videoIndex);
    if (this.data.playStateBool ==false && this.data.videoIndex =='1')
    {
        this.setData({
          playState: '暂停',
          videoIndex: 2,
          playStateBool:true,
        });
      this.videoContent.play();
    console.log('11111');
    }
    // 
    else if (this.data.playStateBool ==false && this.data.videoIndex == '2' )
    {
      this.setData({
        playState: '播放',
        playStateBool: true,
      });
      this.videoContent.play(); 
      console.log('22222');
    } 
    else if (this.data.playStateBool==true && this.data.videoIndex == '2')
    {
      this.setData({
        playState: '暂停',
        playStateBool: false,

      });
      this.videoContent.pause(); 
      console.log('333333');
    }else{

      console.log('44444');
    }
    
    
  },
  videoPlay:function(e)
  {
    if (wx.getStorageSync('LoginSessionKye').userName == undefined) {

      console.log('请登录' + wx.getStorageSync('LoginSessionKye'));

    } else {
      userName = wx.getStorageSync('LoginSessionKye').userName;
      console.log('已登录111' + wx.getStorageSync('LoginSessionKye'));

      console.log('点击播放');
      this.setData({
        playState: '暂停',
        videoIndex: 2,
        playStateBool: true,
      });
      this.videoContent.play();
      console.log('11111');
    }
    
  },
  playEnd:function(e){
    console.log('播放结束');
    var that = this;
    this.setData({
      playState: '播放结束',
      playStateBool: false,
    });
  },
  playVideo: function (e) {
    console.log('播放开始');
    var that = this;
    this.setData({
      playState: '暂停',
      playStateBool: true,

    });
    console.log(this.videoContent.playState);
  
  },

  playpause: function (e) {
    console.log('播放暂停');
    var that = this;
    this.setData({
      playState: '播放',
      playStateBool: false,
    });
    console.log(this.videoContent.playState);

   },
  /**
   * 生命周期函数--监听页面加载
   */
  swichNav:function(e){
    var that=this;

    this.setData({ currentTab: e.currentTarget.dataset.current });
  },
  onGotUserInfo:function(e){
    var that =this;
    console.log(e);
    if(e.detail.userInfo != null)
    {
      App.imageUrl = e.detail.userInfo.avatarUrl;
      App.nikeName = e.detail.userInfo.nikeName;
      App.authorize = true;
      this.setData({ isHaveGetUserInfo:true,});
      wx.setStorageSync('LoginSessionKye', e.detail.userInfo);

    }
    
    console.log('nikeName = ' + wx.getStorageSync('LoginSessionKye').nikeName + this.data.isHaveGetUserInfo);
  },
  swichNav111: function(e){
    var that = this;
    console.log(e);
    if (this.data.currentTab === e.taget.dataset.current)
    {
      return false;
    }else{
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  bindChange:function(e){
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  onLoad: function (options) {
    this.setData({
      navtitle: options.navtitle,
    });
    var that =this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    this.videoContent = wx.createVideoContext('myVideo', this);
    if (wx.getStorageSync('LoginSessionKye').userName == undefined) {

      console.log('请登录' + wx.getStorageSync('LoginSessionKye'));
      this.setData({
        isHaveGetUserInfo:false,
      });
    } else {
      console.log('已登录111' + wx.getStorageSync('LoginSessionKye'));
      this.setData({
        isHaveGetUserInfo: true,
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})